<?php
function concatParams($params) {
    ksort($params);
    $pairs = array();
    foreach($params as $key=>$val) {
        array_push($pairs, $key . '=' . $val);
        // array_push($pairs, $key . '=' . urlencode($val));
    }
    return join('&', $pairs);
}
// 通过给定的url, params, consumer_secret计算出sig
function genSig($pathUrl, $params ,$consumer_secret) {
    $params = concatParams($params);
    $str = $pathUrl.'?'.$params.$consumer_secret;
    return md5($str);
}
// 发送数据多种方式可选
function sendData($url,$params,$type='GET'){
    $ch = curl_init();
    $this_header = array(
        "Content-type: text/html; charset=utf-8"
        );
    curl_setopt($ch,CURLOPT_HTTPHEADER,$this_header);
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
    switch ($type){
        case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, true);break;
        case "POST": curl_setopt($ch, CURLOPT_POST,true);
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;
        case "PUT" : curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;
        case "DELETE":curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;
    }
    $return_str = curl_exec($ch);
    curl_close($ch);
    return $return_str;
}

$params = array(
    'app_id' => 133,
    'timestamp' => time(),
    'app_poi_code' => 31,
    'type' => 1
);
$consumer_secret = 'f32362d0bef2fdab699f9766794cdf87';

$pathUrl = 'http://test.waimaiopen.meituan.com/api/v1/poi/save';

$sig = genSig($pathUrl, $params ,$consumer_secret);

$url = $pathUrl."?sig=".$sig."&".concatParams($params);

// echo $url;die;

$str = sendData($url,$params,'POST');

echo $str;